package com.zhou;

import java.util.*;
import java.util.stream.Collectors;

/**
 * T4
 *
 * @author zhouxianfeng
 * @date 2021-8-17
 */
public class T4 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] s = in.nextLine().split(" ");
        int persons = Integer.parseInt(s[0]);
        int bullets = Integer.parseInt(s[1]);

        int[] attack = new int[persons];
        int[] money = new int[persons];

        s = in.nextLine().split(" ");
        for (int i = 0; i < persons; i++) {
            attack[i] = Integer.parseInt(s[i]);
        }
        s = in.nextLine().split(" ");
        List<Person> list = new ArrayList<>();
        for (int i = 0; i < persons; i++) {
            money[i] = Integer.parseInt(s[i]);
            list.add(new Person(attack[i], money[i]));
        }
        List<Person> attachSorted = list.stream().sorted(new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                return o1.attach - o2.attach;
            }
        }).collect(Collectors.toList());

        for (int i = attachSorted.size() - 1; i > 0; i--) {
            Person person = attachSorted.get(i);
            int attach = person.attach;
            int currbullets = bullets;

            List<Person> people = new ArrayList<>();
            attachSorted.subList(0, i).forEach(t -> people.add(t));
            people.sort(new Comparator<Person>() {
                @Override
                public int compare(Person o1, Person o2) {
                    return o1.money - o2.money;
                }
            });
            for (int j = people.size() - 1; j >= 0; j--) {
                if (currbullets > 0) {
                    Person other = people.get(j);
                    if (attach > other.attach) {
                        person.money += other.money;
                        currbullets -= 1;
                    }
                } else {
                    break;
                }

            }
        }
        Map<Integer, List<Person>> collect1 = attachSorted.stream().collect(Collectors.groupingBy(t -> t.attach));
        for (int i = 0; i < attack.length; i++) {
            System.out.print(collect1.get(attack[i]).get(0).money);
            if (i != attack.length - 1) {
                System.out.print(" ");
            }
        }

    }


    private static class Person {
        Integer attach;
        Integer money;

        public Person(int attach, int money) {
            this.attach = attach;
            this.money = money;
        }

        @Override
        public String toString() {
            return "Person attch=" + attach + ",money=" + money;
        }
    }
}
